<?php
if(!isset($MAIN)){
	include_once("includes/class.ibnfm.php");
	$MAIN = new MAIN();
}
$MAIN->users->checkLogin(true);

if(isset($_POST['txt_email'])){
	if($MAIN->users->setUser($_POST['txt_user_id'],$_POST)){
	?>
	<script type="text/javascript">sendInfo(null,'Dina ändringar har sparats!');toggleFrm('frm_user');</script>
	<?php
	}
	exit();
}
if(isset($_POST['txt_person_firstname'])){
	if($MAIN->persons->setPerson($_POST['txt_person_id'],$_POST)){
	?>
	<script type="text/javascript">sendInfo(null,'Dina ändringar har sparats!');toggleFrm('frm_profile');</script>
	<?php
	}
	exit();
}
?>
<div class="activ">
	<h2>Registrerade profiluppgifter</h2>
	<form name="frm_user" id="frm_user" action="" method="post" onsubmit="return false;">
		<input type="hidden" name="txt_user_id" value="<?php echo($MAIN->currentUser['id']);?>"/>
		<input type="hidden" name="ddl_rights" id="ddl_rights" value="<?php echo($MAIN->currentUser['grouplevel']);?>"/>
	<table cellpadding="0" cellspacing="0">
		<tr>
			<td>E-post address</td>
			<td><input class="required validate-email" type="text" readonly="readonly" name="txt_email" value="<?php echo($MAIN->currentUser['email']);?>"/></td>
		</tr>		
		<tr>
			<td>Lösenord</td>
			<td><input class="required" type="password" readonly="readonly" name="txt_pass" value="<?php echo($MAIN->decode($MAIN->currentUser['drowp']));?>"/></td>
		</tr>
		<tr>
			<td colspan="2" style="text-align:right;">
				<input style="display:none;" type="submit" name="btn_submit" value="Spara" onclick="sendForm('frm_user');"/>
			</td>
		</tr>
	</table>
	</form>	
	<hr/>
	<h2>Användaruppgifter kopplade till profil</h2>	
	<form name="frm_profile" id="frm_profile" action="" method="post" onsubmit="return false;">
		<input type="hidden" name="txt_user_id" value="<?php echo($MAIN->currentUser['id']);?>"/>
		<input type="hidden" name="txt_person_id" value="<?php echo(($MAIN->currentUser['person_id']!=""?$MAIN->currentUser['person_id']:0));?>"/>
		<input type="hidden" name="ddl_association" id="ddl_association" value="<?php echo($MAIN->currentUser['association_id']);?>"/>
	<table cellpadding="0" cellspacing="0">
		<tr>
			<td>Förnamn</td>
			<td><input class="required" type="text" readonly="readonly" name="txt_person_firstname" value="<?php echo(@$MAIN->currentUser['firstname']);?>"/></td>
		</tr>
		<tr>
			<td>Efternamn</td>
			<td><input class="required" type="text" readonly="readonly" name="txt_person_lastname" value="<?php echo(@$MAIN->currentUser['lastname']);?>"/></td>
		</tr>
		<tr>
			<td>Personnummer</td>
			<td><input class="required" type="text" readonly="readonly" name="txt_person_pers" value="<?php echo(@$MAIN->currentUser['pers']);?>"/></td>
		</tr>
		<tr>
			<td>Adress</td>
			<td><input class="required" type="text" readonly="readonly" name="txt_person_address" value="<?php echo(@$MAIN->currentUser['address']);?>"/></td>
		</tr>
		<tr>
			<td>Postnummer</td>
			<td><input class="required" type="text" readonly="readonly" name="txt_person_zip" value="<?php echo(@$MAIN->currentUser['zip']);?>"/></td>
		</tr>
		<tr>
			<td>Ort</td>
			<td><input class="required" type="text" readonly="readonly" name="txt_person_city" value="<?php echo(@$MAIN->currentUser['city']);?>"/></td>
		</tr>
		<tr>
			<td>Telefonnummer</td>
			<td><input class="required" type="text" readonly="readonly" name="txt_person_tel" value="<?php echo(@$MAIN->currentUser['tel']);?>"/></td>
		</tr>
		<tr>
			<td colspan="2" style="text-align:right;">
				<input style="display:none;" type="submit" name="btn_submit" value="Spara" onclick="sendForm('frm_profile');"/>
			</td>
		</tr>
	</table>
	</form>
	<hr/>	
	<h2>Loggar</h2>
	<?php
	$_REQUEST['log_type']="profile";
	include_once("logs.php");
	?>
</div>
<script type="text/javascript">
var toggleFrm = function(what){
	var frm = $(what);
	var inputs = frm.getElements('input');
	if(frm.get('action')!=''){
		inputs.each(function(input,i){			
			if(input.get('type')=='submit'){
				input.setStyle('display','none');
			}else{
				input.set('readonly','readonly');
			}
		});
		frm.set('action','');
	}else{
		inputs.each(function(input,i){		
			if(input.get('readonly') && input.get('name')!='txt_email'){
				input.erase('readonly');
			}
			if(input.get('type')=='submit'){
				input.setStyle('display','inline-block');
			}
		});
		frm.set('action','profile.php');
	}	
}

</script>
